***** RUN DO_MASTER.do ***** do "$Do_files\DO_MASTER.do"

global program "OA_TableB38"
cap log close
cap log using "$Log_files\log_$program$today", replace

**** REPLICATION OF TABLE B.3.8 ****

clear all
set mem 2g
set more off

// Import data

use $Data\data_news_voting, clear

// Get controls

global ctrl_base	"sh_lde lpop_A sh_F sh_F_new sh_cspsup sh_sec sh_ter lmean_reink lmean_reink2 charact_altitude charact_altitude_std sh_active sh_young sh_prot sh_M mk com_property"
global ctrl_plus	"mean_votation lcrSR_F_N"
global fe			"charact_agglo"
global cluster		"charact_agglo"

// Keep correct sample

qui: reghdfe oui endog_mk /// 
	$ctrl_plus ///
	$ctrl_base ///
	if sample_hq00dstr==1, ///
	absorb($fe) cluster($cluster) keepsing	
		
keep if e(sample) == 1
		
// Columns 1-3

foreach dist in 10 20 25{

	acreg oui  $ctrl_base $ctrl_plus  ///
			(endog_mk = instr_dev_mk), ///
			spatial latitude(latitude) longitude(longitude) id(commune) time(year) lag(100000) dist(`dist') lagdist(0) pfe1(charact_agglo) 
	estimates store TSLS_spatial_`dist'
	estadd scalar F_fs=e(widstat)
	estadd scalar surf=_pi*(`dist')^2

}

// Column 4

reghdfe oui $ctrl_plus $ctrl_base (endog_mk = instr_dev_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster district) absorb($fe) stages(first, eform(exp(beta))) keepsing old
estimates store TSLS_distr
estadd scalar F_fs=e(widstat)
estadd scalar surf=41285/148

// Column 5

reghdfe oui $ctrl_plus $ctrl_base (endog_mk = instr_dev_mk) ///
	if sample_hq00dstr==1, ///
	vce(cluster canton) absorb($fe) stages(first, eform(exp(beta))) keepsing old
estimates store TSLS_canton
estadd scalar F_fs=e(widstat)
estadd scalar surf=41285/26

// Labels

la var endog_mk 		"Crime News Exposure ($ \mathtt{CNE} $)"
la var lcrSR_F_N 		"[0.1em] Local $ \mathtt{CPD} $"
la var mean_votation 	"[0.1em] Past Votes Outcome"

// Table

estout TSLS_spatial_10 TSLS_spatial_20 TSLS_spatial_25 TSLS_distr TSLS_canton ///
	using "$Results\\$program.tex", replace style(tex) type label	///
	cells(b(star fmt(3)) se(par fmt(3)))  ///
	stats(N F_fs surf, lab("Observations" "First-stage F-statistic" "Average surface (sq. km.)") fmt(0 2 1)) ///
	collabels(none) ///
	mlabels(, span none prefix(\multicolumn{@span}{c}{) suffix(})) ///
	msign(--) starlevels($^c$ .1 $^b$ .05 $^a$ .01) ///
	keep(endog_mk lcrSR_F_N mean_votation) ///
	order(endog_mk lcrSR_F_N mean_votation) ///
	title(News and voting: Spatial clustering) ///	
	prehead("\begin{table}[!h]" ///
	"\begin{center}" ///
	"\begin{threeparttable}" ///
	"\begin{footnotesize}" ///
	"\caption{\small{@title}\label{$program}}" ///
	"\begin{tabular*}{\columnwidth}{@{\extracolsep{\stretch{1}}}l*{@M}{c}@{}}" ///
	"\hline" "\hline" ///
	"\\" ///
	"Specification 				&\multicolumn{5}{c}{Two-Stage Least-Squares} \\" ///
	"							\cmidrule(lr){2-6}	" ///
	"Dependent Variable 		&\multicolumn{5}{c}{Minaret Ban approval (\%Yes)} \\" ///
	"							\cmidrule(lr){2-6}" ///
	"%Clustering 		&\multicolumn{3}{c}{Spatial}	&\multicolumn{1}{c}{District}	&\multicolumn{1}{c}{Canton} 	\\" ///
	"Clustering	 		&\multicolumn{1}{c}{10 km}	&\multicolumn{1}{c}{20 km}	&\multicolumn{1}{c}{25 km}	&\multicolumn{1}{c}{District}	&\multicolumn{1}{c}{Canton} 	\\" ///
	"					\cmidrule(lr){2-4} 						\cmidrule(lr){5-5}				\cmidrule(lr){6-6}			" ///
	"					&\multicolumn{1}{c}{(1)} 				&\multicolumn{1}{c}{(2)}  				&\multicolumn{1}{c}{(3)} 				&\multicolumn{1}{c}{(4)}  		&\multicolumn{1}{c}{(5)} 	\\") ///
	posthead("\hline" ///
	"\\") ///
	prefoot("\\" ///
	"\hline") ///
	postfoot( ///
	"\hline" "\hline" ///
	"\end{tabular*}" /// 
	"\end{footnotesize}" ///
	"\begin{tablenotes}[normal,flushleft]" ///
	"\begin{scriptsize}" ///
	"\item \emph{Notes}:" /// 
	"The unit of observation is a municipality. " ///
	"Spatially clustered standard errors in parentheses in Columns (1) to (3). " ///
	"Standard errors clustered at district and canton level in parentheses in Columns (4) and (5). " ///
	"{$^c$} significant at 10\%; {$^b$} significant at 5\%; {$^a$} significant at 1\%. " ///
	"All columns present the second-stage of the 2SLS estimation based on the instrument computed as the short-run Crime Propensity Differential ($ \mathtt{CPD} $) in newspaper " ///
	"headquarter areas in deviation from its long-run counterpart  ($ \mathtt{\Delta HQC}_{m} $). " ///
	"All regressions include the full vector of controls of Table \ref{Main_Table2}. " ///
	"" ///
	"\end{scriptsize}" ///
	"\end{tablenotes}" ///
	"\end{threeparttable}" ///
	"\end{center}" ///
	"\end{table}")

cap log close
